package GUI;

import ModelLayer.*;
import CtrlLayer.*;

import java.util.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class StatisticsGUI extends JFrame implements ActionListener {
    private Container container;
    private JPanel panelStatistics;
    private JPanel panelEmployeeStatistics;
    private JPanel panelEmployeeStatistics2;
    private JPanel panelProductStatistics;
    private JPanel panelProductStatistics2;
    private JPanel panelBestSeller;
    private JPanel panelBestLeaser;
    private JPanel panelCustomerStatistics;
    private JPanel panelCustomerStatistics2;
    private JPanel panelMostSpendingCustomer;
    private JButton back;
    private EmployeeController employeeController;
    private ProductController productController;
    private CustomerController customerController;
    private Statistics statistics;

    public StatisticsGUI() {
        panelStatistics = new JPanel(new GridBagLayout());
        panelEmployeeStatistics = new JPanel(new GridBagLayout());
        panelEmployeeStatistics2 = new JPanel(new GridBagLayout());
        panelBestSeller = new JPanel(new GridBagLayout());
        panelBestLeaser = new JPanel(new GridBagLayout());
        panelCustomerStatistics = new JPanel(new GridBagLayout());
        panelCustomerStatistics2 = new JPanel(new GridBagLayout());
        panelMostSpendingCustomer = new JPanel(new GridBagLayout());
        panelProductStatistics = new JPanel(new GridBagLayout());
        panelProductStatistics2 = new JPanel(new GridBagLayout());
        employeeController = new EmployeeController();
        productController = new ProductController();
        customerController = new CustomerController();
        statistics = new Statistics();

        this.setTitle("Vestbjerg company system");
        this.setLocation(300,50);
        this.setVisible(true);
        this.setSize(400,470);
        this.setResizable(false);

        statisticsMainMenu();
        this.getContentPane().add(panelStatistics, BorderLayout.NORTH);
    }

    public void actionPerformed(ActionEvent e){

    }

    public void makeStatisticsMenu() {
        GridBagConstraints gbc = new GridBagConstraints();

        JButton employeeStatistics = new JButton("Employee Statistics");
        employeeStatistics.setPreferredSize(new Dimension(150,25));
        employeeStatistics.addActionListener(new ActionListener()
            {
                public void actionPerformed(ActionEvent e){
                    container = getContentPane();
                    container.removeAll();
                    employeeStatistics();
                    container.invalidate();
                    container.revalidate();
                    container.repaint();
                    container.setVisible(true);
                }
            }
        );
        gbc.gridx = 0;
        gbc.gridy = 1;
        gbc.insets = new Insets(5,5,5,5);
        panelStatistics.add(employeeStatistics, gbc);

        JButton productStatistics = new JButton("Product Statistics");
        productStatistics.setPreferredSize(new Dimension(150,25));
        productStatistics.addActionListener(new ActionListener()
            {
                public void actionPerformed(ActionEvent e){
                    container = getContentPane();
                    container.removeAll();
                    productStatistics();
                    container.invalidate();
                    container.revalidate();
                    container.repaint();
                    container.setVisible(true);
                }
            }
        );
        gbc.gridx = 0;
        gbc.gridy = 2;
        gbc.insets = new Insets(5,5,5,5);
        panelStatistics.add(productStatistics, gbc);

        JButton mostSoldProduct = new JButton("Most Sold Product");
        mostSoldProduct.setPreferredSize(new Dimension(150,25));
        mostSoldProduct.addActionListener(new ActionListener()
            {
                public void actionPerformed(ActionEvent e){
                    container = getContentPane();
                    container.removeAll();
                    bestSellerStatistics();
                    container.invalidate();
                    container.revalidate();
                    container.repaint();
                    container.setVisible(true);
                }
            }
        );
        gbc.gridx = 0;
        gbc.gridy = 3;
        gbc.insets = new Insets(5,5,5,5);
        panelStatistics.add(mostSoldProduct, gbc);

        JButton mostLeasedProduct = new JButton("Most Leased Product");
        mostLeasedProduct.setPreferredSize(new Dimension(150,25));
        mostLeasedProduct.addActionListener(new ActionListener()
            {
                public void actionPerformed(ActionEvent e){
                    container = getContentPane();
                    container.removeAll();
                    bestLeaserStatistics();
                    container.invalidate();
                    container.revalidate();
                    container.repaint();
                    container.setVisible(true);
                }
            }
        );
        gbc.gridx = 0;
        gbc.gridy = 4;
        gbc.insets = new Insets(5,5,5,5);
        panelStatistics.add(mostLeasedProduct, gbc);

        JButton customerStatistics = new JButton("Customer Statistics");
        customerStatistics.setPreferredSize(new Dimension(150,25));
        customerStatistics.addActionListener(new ActionListener()
            {
                public void actionPerformed(ActionEvent e){
                    container = getContentPane();
                    container.removeAll();
                    customerStatistics();
                    container.invalidate();
                    container.revalidate();
                    container.repaint();
                    container.setVisible(true);
                }
            }
        );
        gbc.gridx = 0;
        gbc.gridy = 5;
        gbc.insets = new Insets(5,5,5,5);
        panelStatistics.add(customerStatistics, gbc);

        JButton mostSpendingCustomer = new JButton("Most Spending Customer");
        mostSpendingCustomer.setPreferredSize(new Dimension(150,25));
        mostSpendingCustomer.addActionListener(new ActionListener()
            {
                public void actionPerformed(ActionEvent e){
                    container = getContentPane();
                    container.removeAll();
                    mostSpendingCustomerStatistics();
                    container.invalidate();
                    container.revalidate();
                    container.repaint();
                    container.setVisible(true);
                }
            }
        );
        gbc.gridx = 0;
        gbc.gridy = 6;
        gbc.insets = new Insets(5,5,5,5);
        panelStatistics.add(mostSpendingCustomer, gbc);

        JButton back = new JButton("Close");
        back.setPreferredSize(new Dimension(150, 25));
        back.addActionListener(new ActionListener()
            {
                public void actionPerformed(ActionEvent e){
                    dispose();
                }
            }
        );
        gbc.gridx = 0;
        gbc.gridy = 7;
        gbc.insets = new Insets(5,5,5,5);
        panelStatistics.add(back, gbc);
    }

    public void statisticsMainMenu()
    {
        makeStatisticsMenu();
        this.getContentPane().add(panelStatistics,BorderLayout.NORTH);
    }

    public void employeeStatistic()
    {
        JTextField textId = new JTextField();
        JLabel labelId;
        JLabel errorMessage;
        JButton find;
        JButton back;
        GridBagConstraints gbc = new GridBagConstraints();

        textId.setText("");

        labelId = new JLabel("ID:", JLabel.RIGHT);
        labelId.setPreferredSize(new Dimension(100, 25));
        gbc.gridx = 0;
        gbc.gridy = 0;
        gbc.insets = new Insets(5,5,5,5);
        panelEmployeeStatistics.add(labelId, gbc);

        gbc.gridx = 1;
        gbc.gridy = 0;
        gbc.insets = new Insets(5,5,5,5);
        textId.setPreferredSize(new Dimension(100,25));
        panelEmployeeStatistics.add(textId,gbc);

        errorMessage = new JLabel("", JLabel.RIGHT);
        errorMessage.setPreferredSize(new Dimension(100, 25));
        gbc.gridx = 0;
        gbc.gridy = 1;
        gbc.insets = new Insets(5,5,5,5);
        panelEmployeeStatistics.add(errorMessage, gbc);

        find = new JButton("Search");
        find.addActionListener(new ActionListener()
            {
                public void actionPerformed(ActionEvent e){
                    try{
                        container = getContentPane();
                        container.removeAll();
                        employeeStatisticsSecond(Integer.parseInt(textId.getText()));
                        container.invalidate();
                        container.revalidate();
                        container.repaint();
                        container.setVisible(true);
                        textId.setText("");
                        errorMessage.setText("");
                    }catch(Exception ex){
                        container = getContentPane();
                        container.removeAll();
                        employeeStatistics();
                        container.invalidate();
                        container.revalidate();
                        container.repaint();
                        container.setVisible(true);
                        textId.setText("");
                        errorMessage.setText("No employee!");
                    }
                }
            }
        );
        gbc.gridx = 0;
        gbc.gridy = 2;
        gbc.insets = new Insets(5,5,5,5);
        find.setPreferredSize(new Dimension(100,25));
        panelEmployeeStatistics.add(find,gbc);

        back = new JButton("Back");
        back.addActionListener(new ActionListener()
            {
                public void actionPerformed(ActionEvent e){
                    container = getContentPane();
                    container.removeAll();
                    statisticsMainMenu();
                    container.invalidate();
                    container.revalidate();
                    container.repaint();
                    container.setVisible(true);
                    textId.setText("");
                    errorMessage.setText("");
                }
            }
        );
        gbc.gridx = 1;
        gbc.gridy = 2;
        gbc.insets = new Insets(5,5,5,5);
        back.setPreferredSize(new Dimension(100,25));
        panelEmployeeStatistics.add(back,gbc);
    }  

    public void employeeStatistics()
    {
        employeeStatistic();
        this.getContentPane().add(panelEmployeeStatistics, BorderLayout.NORTH);
    }

    public void employeeStatisticSecond(int id)
    {
        JTextField textId = new JTextField();
        JTextField textName = new JTextField();
        JTextField textEmail = new JTextField();
        JTextField textPhoneNumber = new JTextField();
        JTextField textDepartment = new JTextField();
        JTextField textSales = new JTextField();
        JTextField textLeases = new JTextField();
        JTextField textOrders = new JTextField();
        JTextField textTotal = new JTextField();
        JLabel labelId;
        JLabel labelName;
        JLabel labelEmail;
        JLabel labelPhoneNumber;
        JLabel labelDepartment;
        JLabel labelSales;
        JLabel labelLeases;
        JLabel labelOrders;
        JLabel labelTotal;
        JButton ok;
        GridBagConstraints gbc = new GridBagConstraints();

        textId.setEditable(false);
        textName.setEditable(false);
        textEmail.setEditable(false);
        textPhoneNumber.setEditable(false);
        textDepartment.setEditable(false);
        textSales.setEditable(false);
        textLeases.setEditable(false);
        textOrders.setEditable(false);
        textTotal.setEditable(false);

        textId.setText(Integer.toString(id));
        textName.setText(employeeController.findEmployee(id).getName());
        textEmail.setText(employeeController.findEmployee(id).getEmail());
        textPhoneNumber.setText(employeeController.findEmployee(id).getPhoneNumber());
        textDepartment.setText(employeeController.findEmployee(id).getDepartment());
        textSales.setText(Integer.toString(employeeController.findEmployee(id).getSold()));
        textLeases.setText(Integer.toString(employeeController.findEmployee(id).getLeased()));
        textOrders.setText(Integer.toString(employeeController.findEmployee(id).getOrdered()));
        textTotal.setText(Double.toString(employeeController.findEmployee(id).getIncome()));

        labelId = new JLabel("ID:", JLabel.RIGHT);
        labelId.setPreferredSize(new Dimension(100, 25));
        gbc.gridx = 0;
        gbc.gridy = 0;
        gbc.insets = new Insets(5,5,5,5);
        panelEmployeeStatistics2.add(labelId, gbc);

        gbc.gridx = 1;
        gbc.gridy = 0;
        gbc.insets = new Insets(5,5,5,5);
        textId.setPreferredSize(new Dimension(100,25));
        panelEmployeeStatistics2.add(textId,gbc);

        labelName = new JLabel("Name:", JLabel.RIGHT);
        labelName.setPreferredSize(new Dimension(100, 25));
        gbc.gridx = 0;
        gbc.gridy = 1;
        gbc.insets = new Insets(5,5,5,5);
        panelEmployeeStatistics2.add(labelName, gbc);

        gbc.gridx = 1;
        gbc.gridy = 1;
        gbc.insets = new Insets(5,5,5,5);
        textName.setPreferredSize(new Dimension(100,25));
        panelEmployeeStatistics2.add(textName,gbc);

        labelEmail = new JLabel("E-Mail:", JLabel.RIGHT);
        labelEmail.setPreferredSize(new Dimension(100, 25));
        gbc.gridx = 0;
        gbc.gridy = 2;
        gbc.insets = new Insets(5,5,5,5);
        panelEmployeeStatistics2.add(labelEmail, gbc);

        gbc.gridx = 1;
        gbc.gridy = 2;
        gbc.insets = new Insets(5,5,5,5);
        textEmail.setPreferredSize(new Dimension(100,25));
        panelEmployeeStatistics2.add(textEmail,gbc);

        labelPhoneNumber = new JLabel("Phone number:", JLabel.RIGHT);
        labelPhoneNumber.setPreferredSize(new Dimension(100, 25));
        gbc.gridx = 0;
        gbc.gridy = 3;
        gbc.insets = new Insets(5,5,5,5);
        panelEmployeeStatistics2.add(labelPhoneNumber, gbc);

        gbc.gridx = 1;
        gbc.gridy = 3;
        gbc.insets = new Insets(5,5,5,5);
        textPhoneNumber.setPreferredSize(new Dimension(100,25));
        panelEmployeeStatistics2.add(textPhoneNumber,gbc);

        labelDepartment = new JLabel("Department:", JLabel.RIGHT);
        labelDepartment.setPreferredSize(new Dimension(100, 25));
        gbc.gridx = 0;
        gbc.gridy = 4;
        gbc.insets = new Insets(5,5,5,5);
        panelEmployeeStatistics2.add(labelDepartment, gbc);

        gbc.gridx = 1;
        gbc.gridy = 4;
        gbc.insets = new Insets(5,5,5,5);
        textDepartment.setPreferredSize(new Dimension(100,25));
        panelEmployeeStatistics2.add(textDepartment,gbc);

        labelSales = new JLabel("Sales completed:", JLabel.RIGHT);
        labelSales.setPreferredSize(new Dimension(100,25));
        gbc.gridx = 0;
        gbc.gridy = 5;
        gbc.insets = new Insets(5,5,5,5);
        panelEmployeeStatistics2.add(labelSales,gbc);

        gbc.gridx = 1;
        gbc.gridy = 5;
        gbc.insets = new Insets(5,5,5,5);
        textSales.setPreferredSize(new Dimension(100,25));
        panelEmployeeStatistics2.add(textSales,gbc);
        
        labelLeases = new JLabel("Leases completed:", JLabel.RIGHT);
        labelLeases.setPreferredSize(new Dimension(100,25));
        gbc.gridx = 0;
        gbc.gridy = 6;
        gbc.insets = new Insets(5,5,5,5);
        panelEmployeeStatistics2.add(labelLeases,gbc);
        
        gbc.gridx = 1;
        gbc.gridy = 6;
        textLeases.setPreferredSize(new Dimension(100,25));
        panelEmployeeStatistics2.add(textLeases,gbc);
        
        labelOrders = new JLabel("Orders completed:", JLabel.RIGHT);
        labelOrders.setPreferredSize(new Dimension(100,25));
        gbc.gridx = 0;
        gbc.gridy = 7;
        gbc.insets = new Insets(5,5,5,5);
        panelEmployeeStatistics2.add(labelOrders, gbc);
        
        gbc.gridx = 1;
        gbc.gridy = 7;
        textOrders.setPreferredSize(new Dimension(100,25));
        panelEmployeeStatistics2.add(textOrders, gbc);
        
        labelTotal = new JLabel("Money generated:", JLabel.RIGHT);
        labelTotal.setPreferredSize(new Dimension(100,25));
        gbc.gridx = 0;
        gbc.gridy = 8;
        gbc.insets = new Insets(5,5,5,5);
        panelEmployeeStatistics2.add(labelTotal, gbc);
        
        gbc.gridx = 1;
        gbc.gridy = 8;
        textTotal.setPreferredSize(new Dimension(100,25));
        panelEmployeeStatistics2.add(textTotal, gbc);
        
        ok = new JButton("OK");
        ok.addActionListener(new ActionListener()
            {
                public void actionPerformed(ActionEvent e){
                    container = getContentPane();
                    container.removeAll();
                    employeeStatistics();
                    container.invalidate();
                    container.revalidate();
                    container.repaint();
                    container.setVisible(true);
                }
            }
        );
        gbc.gridx = 0;
        gbc.gridy = 9;
        gbc.insets = new Insets(5,5,5,5);
        ok.setPreferredSize(new Dimension(100,25));
        panelEmployeeStatistics2.add(ok,gbc);
    }

    public void employeeStatisticsSecond(int id)
    {
        employeeStatisticSecond(id);
        this.getContentPane().add(panelEmployeeStatistics2, BorderLayout.NORTH);
    }
    
    public void productStatistic()
    {
        JTextField textBarcode = new JTextField();
        JLabel labelBarcode;
        JLabel errorMessage;
        JButton find;
        JButton back;
        GridBagConstraints gbc = new GridBagConstraints();

        textBarcode.setText("");

        labelBarcode = new JLabel("Barcode:", JLabel.RIGHT);
        labelBarcode.setPreferredSize(new Dimension(100, 25));
        gbc.gridx = 0;
        gbc.gridy = 0;
        gbc.insets = new Insets(5,5,5,5);
        panelProductStatistics.add(labelBarcode, gbc);

        gbc.gridx = 1;
        gbc.gridy = 0;
        gbc.insets = new Insets(5,5,5,5);
        textBarcode.setPreferredSize(new Dimension(100,25));
        panelProductStatistics.add(textBarcode,gbc);

        errorMessage = new JLabel("", JLabel.RIGHT);
        errorMessage.setPreferredSize(new Dimension(100, 25));
        gbc.gridx = 0;
        gbc.gridy = 1;
        gbc.insets = new Insets(5,5,5,5);
        panelProductStatistics.add(errorMessage, gbc);

        find = new JButton("Search");
        find.addActionListener(new ActionListener()
            {
                public void actionPerformed(ActionEvent e){
                    try{
                        container = getContentPane();
                        container.removeAll();
                        productStatisticsSecond(Integer.parseInt(textBarcode.getText()));
                        container.invalidate();
                        container.revalidate();
                        container.repaint();
                        container.setVisible(true);
                        textBarcode.setText("");
                        errorMessage.setText("");
                    }catch(Exception ex){
                        container = getContentPane();
                        container.removeAll();
                        productStatistics();
                        container.invalidate();
                        container.revalidate();
                        container.repaint();
                        container.setVisible(true);
                        textBarcode.setText("");
                        errorMessage.setText("No product!");
                    }
                }
            }
        );
        gbc.gridx = 0;
        gbc.gridy = 2;
        gbc.insets = new Insets(5,5,5,5);
        find.setPreferredSize(new Dimension(100,25));
        panelProductStatistics.add(find,gbc);

        back = new JButton("Back");
        back.addActionListener(new ActionListener()
            {
                public void actionPerformed(ActionEvent e){
                    container = getContentPane();
                    container.removeAll();
                    statisticsMainMenu();
                    container.invalidate();
                    container.revalidate();
                    container.repaint();
                    container.setVisible(true);
                    textBarcode.setText("");
                    errorMessage.setText("");
                }
            }
        );
        gbc.gridx = 1;
        gbc.gridy = 2;
        gbc.insets = new Insets(5,5,5,5);
        back.setPreferredSize(new Dimension(100,25));
        panelProductStatistics.add(back,gbc);
    }
    
    public void productStatistics()
    {
        productStatistic();
        this.getContentPane().add(panelProductStatistics, BorderLayout.NORTH);
    }
    
    public void productStatisticSecond(int barcode)
    {
        JTextField textBarcode = new JTextField();
        JTextField textName = new JTextField();
        JTextField textSold = new JTextField();
        JTextField textLeased = new JTextField();
        JTextField textOrdered = new JTextField();
        JTextField textIncome = new JTextField();
        JTextField textOutcome = new JTextField();
        JTextField textTotal = new JTextField();
        JLabel labelBarcode;
        JLabel labelName;
        JLabel labelSold;
        JLabel labelLeased;
        JLabel labelOrdered;
        JLabel labelIncome;
        JLabel labelOutcome;
        JLabel labelTotal;
        JButton ok;
        GridBagConstraints gbc = new GridBagConstraints();

        textBarcode.setEditable(false); 
        textName.setEditable(false);
        textSold.setEditable(false);
        textLeased.setEditable(false);
        textOrdered.setEditable(false);
        textIncome.setEditable(false);
        textOutcome.setEditable(false);
        textTotal.setEditable(false);
        
        double income = 0;
        income += productController.findProduct(barcode).getSellingPrice() * productController.findProduct(barcode).getSold();
        income += productController.findProduct(barcode).getSellingPrice() * productController.findProduct(barcode).getLeased();
        
        double outcome = 0;
        outcome = productController.findProduct(barcode).getPriceForDiscount() * productController.findProduct(barcode).getOrdered();
        
        textBarcode.setText(Integer.toString(productController.findProduct(barcode).getBarcode()));
        textName.setText(productController.findProduct(barcode).getName());
        textSold.setText(Integer.toString(productController.findProduct(barcode).getSold()));
        textLeased.setText(Integer.toString(productController.findProduct(barcode).getLeased()));
        textOrdered.setText(Integer.toString(productController.findProduct(barcode).getOrdered()));
        textIncome.setText(Double.toString(income));
        textOutcome.setText(Double.toString(outcome));
        textTotal.setText(Double.toString(income - outcome));
        
        labelBarcode = new JLabel("Barcode:", JLabel.RIGHT);
        labelBarcode.setPreferredSize(new Dimension(130, 25));
        gbc.gridx = 0;
        gbc.gridy = 0;
        gbc.insets = new Insets(5,5,5,5);
        panelProductStatistics2.add(labelBarcode, gbc);

        gbc.gridx = 1;
        gbc.gridy = 0;
        gbc.insets = new Insets(5,5,5,5);
        textBarcode.setPreferredSize(new Dimension(100,25));
        panelProductStatistics2.add(textBarcode,gbc);

        labelName = new JLabel("Name:", JLabel.RIGHT);
        labelName.setPreferredSize(new Dimension(130, 25));
        gbc.gridx = 0;
        gbc.gridy = 1;
        gbc.insets = new Insets(5,5,5,5);
        panelProductStatistics2.add(labelName, gbc);

        gbc.gridx = 1;
        gbc.gridy = 1;
        gbc.insets = new Insets(5,5,5,5);
        textName.setPreferredSize(new Dimension(100,25));
        panelProductStatistics2.add(textName,gbc);

        labelSold = new JLabel("Sold:", JLabel.RIGHT);
        labelSold.setPreferredSize(new Dimension(130, 25));
        gbc.gridx = 0;
        gbc.gridy = 2;
        gbc.insets = new Insets(5,5,5,5);
        panelProductStatistics2.add(labelSold, gbc);

        gbc.gridx = 1;
        gbc.gridy = 2;
        gbc.insets = new Insets(5,5,5,5);
        textSold.setPreferredSize(new Dimension(100,25));
        panelProductStatistics2.add(textSold,gbc);

        labelLeased = new JLabel("Leased:", JLabel.RIGHT);
        labelLeased.setPreferredSize(new Dimension(130, 25));
        gbc.gridx = 0;
        gbc.gridy = 3;
        gbc.insets = new Insets(5,5,5,5);
        panelProductStatistics2.add(labelLeased, gbc);

        gbc.gridx = 1;
        gbc.gridy = 3;
        gbc.insets = new Insets(5,5,5,5);
        textLeased.setPreferredSize(new Dimension(100,25));
        panelProductStatistics2.add(textLeased,gbc);

        labelOrdered = new JLabel("Ordered:", JLabel.RIGHT);
        labelOrdered.setPreferredSize(new Dimension(130, 25));
        gbc.gridx = 0;
        gbc.gridy = 4;
        gbc.insets = new Insets(5,5,5,5);
        panelProductStatistics2.add(labelOrdered, gbc);

        gbc.gridx = 1;
        gbc.gridy = 4;
        gbc.insets = new Insets(5,5,5,5);
        textOrdered.setPreferredSize(new Dimension(100,25));
        panelProductStatistics2.add(textOrdered,gbc);

        labelIncome = new JLabel("Income:", JLabel.RIGHT);
        labelIncome.setPreferredSize(new Dimension(130, 25));
        gbc.gridx = 0;
        gbc.gridy = 5;
        gbc.insets = new Insets(5,5,5,5);
        panelProductStatistics2.add(labelIncome, gbc);

        gbc.gridx = 1;
        gbc.gridy = 5;
        gbc.insets = new Insets(5,5,5,5);
        textIncome.setPreferredSize(new Dimension(100,25));
        panelProductStatistics2.add(textIncome,gbc);

        labelOutcome = new JLabel("Outcome:", JLabel.RIGHT);
        labelOutcome.setPreferredSize(new Dimension(130, 25));
        gbc.gridx = 0;
        gbc.gridy = 6;
        gbc.insets = new Insets(5,5,5,5);
        panelProductStatistics2.add(labelOutcome, gbc);

        gbc.gridx = 1;
        gbc.gridy = 6;
        gbc.insets = new Insets(5,5,5,5);
        textOutcome.setPreferredSize(new Dimension(100,25));
        panelProductStatistics2.add(textOutcome,gbc);

        labelTotal = new JLabel("Total:", JLabel.RIGHT);
        labelTotal.setPreferredSize(new Dimension(130, 25));
        gbc.gridx = 0;
        gbc.gridy = 7;
        gbc.insets = new Insets(5,5,5,5);
        panelProductStatistics2.add(labelTotal, gbc);

        gbc.gridx = 1;
        gbc.gridy = 7;
        gbc.insets = new Insets(5,5,5,5);
        textTotal.setPreferredSize(new Dimension(100,25));
        panelProductStatistics2.add(textTotal,gbc);

        ok = new JButton("OK");
        ok.addActionListener(new ActionListener()
            {
                public void actionPerformed(ActionEvent e){
                    container = getContentPane();
                    container.removeAll();
                    productStatistics();
                    container.invalidate();
                    container.revalidate();
                    container.repaint();
                    container.setVisible(true);
                }
            }
        );
        gbc.gridx = 0;
        gbc.gridy = 8;
        gbc.insets = new Insets(5,5,5,5);
        ok.setPreferredSize(new Dimension(100,25));
        panelProductStatistics2.add(ok,gbc);
    }
    
    public void productStatisticsSecond(int barcode)
    {
        productStatisticSecond(barcode);
        this.getContentPane().add(panelProductStatistics2, BorderLayout.NORTH);
    }
    
    public void bestSeller(int barcode)
    {
        productStatisticsSecond(barcode);
    }
    
    public void bestSellerStatistics()
    {
        bestSeller(statistics.bestSellerStatistics());
        //this.getContentPane().add(panelBestSeller, BorderLayout.NORTH);
    }
    
    public void bestLeaser(int barcode)
    {
        productStatisticsSecond(barcode);
    }
    
    public void bestLeaserStatistics()
    {
        bestLeaser(statistics.bestLeasserStatistics());
        //this.getContentPane().add(panelBestLeaser, BorderLayout.NORTH);
    }
    
    public void customerStatistic()
    {
        JTextField textId = new JTextField();
        JLabel labelId;
        JLabel errorMessage;
        JButton find;
        JButton back;
        GridBagConstraints gbc = new GridBagConstraints();

        textId.setText("");

        labelId = new JLabel("ID:", JLabel.RIGHT);
        labelId.setPreferredSize(new Dimension(100, 25));
        gbc.gridx = 0;
        gbc.gridy = 0;
        gbc.insets = new Insets(5,5,5,5);
        panelCustomerStatistics.add(labelId, gbc);

        gbc.gridx = 1;
        gbc.gridy = 0;
        gbc.insets = new Insets(5,5,5,5);
        textId.setPreferredSize(new Dimension(100,25));
        panelCustomerStatistics.add(textId,gbc);

        errorMessage = new JLabel("", JLabel.RIGHT);
        errorMessage.setPreferredSize(new Dimension(100, 25));
        gbc.gridx = 0;
        gbc.gridy = 1;
        gbc.insets = new Insets(5,5,5,5);
        panelCustomerStatistics.add(errorMessage, gbc);

        find = new JButton("Search");
        find.addActionListener(new ActionListener()
            {
                public void actionPerformed(ActionEvent e){
                    try{
                        container = getContentPane();
                        container.removeAll();
                        customerStatisticsSecond(Integer.parseInt(textId.getText()));
                        container.invalidate();
                        container.revalidate();
                        container.repaint();
                        container.setVisible(true);
                        textId.setText("");
                        errorMessage.setText("");
                    }catch(Exception ex){
                        container = getContentPane();
                        container.removeAll();
                        customerStatistics();
                        container.invalidate();
                        container.revalidate();
                        container.repaint();
                        container.setVisible(true);
                        errorMessage.setText("No customer!");
                        textId.setText("");
                    }
                }
            }
        );
        gbc.gridx = 0;
        gbc.gridy = 2;
        gbc.insets = new Insets(5,5,5,5);
        find.setPreferredSize(new Dimension(100,25));
        panelCustomerStatistics.add(find,gbc);

        back = new JButton("Back");
        back.addActionListener(new ActionListener()
            {
                public void actionPerformed(ActionEvent e){
                    container = getContentPane();
                    container.removeAll();
                    statisticsMainMenu();
                    container.invalidate();
                    container.revalidate();
                    container.repaint();
                    container.setVisible(true);

                    textId.setText("");
                    errorMessage.setText("");
                }
            }
        );
        gbc.gridx = 1;
        gbc.gridy = 2;
        gbc.insets = new Insets(5,5,5,5);
        back.setPreferredSize(new Dimension(100,25));
        panelCustomerStatistics.add(back,gbc);
    }
    
    public void customerStatistics()
    {
        customerStatistic();
        this.getContentPane().add(panelCustomerStatistics, BorderLayout.NORTH);
    }
    
    public void customerStatisticSecond(int id)
    {
        JTextField textId = new JTextField();
        JTextField textName = new JTextField();
        JTextField textEmail = new JTextField();
        JTextField textPhoneNumber = new JTextField();
        JTextField textAddress = new JTextField();
        JTextField textDiscount = new JTextField();
        JTextField textBought = new JTextField();
        JTextField textLeased = new JTextField();
        JTextField textTotal = new JTextField();
        JLabel labelId;
        JLabel labelName;
        JLabel labelEmail;
        JLabel labelPhoneNumber;
        JLabel labelAddress;
        JLabel labelDiscount;
        JLabel labelBought;
        JLabel labelLeased;
        JLabel labelTotal;
        JButton ok;
        GridBagConstraints gbc = new GridBagConstraints();

        textId.setEditable(false);
        textName.setEditable(false);
        textEmail.setEditable(false);
        textPhoneNumber.setEditable(false);
        textAddress.setEditable(false);
        textDiscount.setEditable(false);
        textBought.setEditable(false);
        textLeased.setEditable(false);
        textTotal.setEditable(false);

        textId.setText(Integer.toString(id));
        textName.setText(customerController.findCustomer(id).getName());
        textEmail.setText(customerController.findCustomer(id).getEmail());
        textPhoneNumber.setText(customerController.findCustomer(id).getPhoneNumber());
        textAddress.setText(customerController.findCustomer(id).getAddress());
        textDiscount.setText(Integer.toString(customerController.findCustomer(id).getDiscount()));
        textBought.setText(Integer.toString(customerController.findCustomer(id).getBought()));
        textLeased.setText(Integer.toString(customerController.findCustomer(id).getRented()));
        textTotal.setText(Double.toString(customerController.findCustomer(id).getIncome()));
        
        labelId = new JLabel("ID:", JLabel.RIGHT);
        labelId.setPreferredSize(new Dimension(100, 25));
        gbc.gridx = 0;
        gbc.gridy = 0;
        gbc.insets = new Insets(5,5,5,5);
        panelCustomerStatistics2.add(labelId, gbc);

        gbc.gridx = 1;
        gbc.gridy = 0;
        gbc.insets = new Insets(5,5,5,5);
        textId.setPreferredSize(new Dimension(100,25));
        panelCustomerStatistics2.add(textId,gbc);

        labelName = new JLabel("Name:", JLabel.RIGHT);
        labelName.setPreferredSize(new Dimension(100, 25));
        gbc.gridx = 0;
        gbc.gridy = 1;
        gbc.insets = new Insets(5,5,5,5);
        panelCustomerStatistics2.add(labelName, gbc);

        gbc.gridx = 1;
        gbc.gridy = 1;
        gbc.insets = new Insets(5,5,5,5);
        textName.setPreferredSize(new Dimension(100,25));
        panelCustomerStatistics2.add(textName,gbc);

        labelEmail = new JLabel("E-Mail:", JLabel.RIGHT);
        labelEmail.setPreferredSize(new Dimension(100, 25));
        gbc.gridx = 0;
        gbc.gridy = 2;
        gbc.insets = new Insets(5,5,5,5);
        panelCustomerStatistics2.add(labelEmail, gbc);

        gbc.gridx = 1;
        gbc.gridy = 2;
        gbc.insets = new Insets(5,5,5,5);
        textEmail.setPreferredSize(new Dimension(100,25));
        panelCustomerStatistics2.add(textEmail,gbc);

        labelPhoneNumber = new JLabel("Phone number:", JLabel.RIGHT);
        labelPhoneNumber.setPreferredSize(new Dimension(100, 25));
        gbc.gridx = 0;
        gbc.gridy = 3;
        gbc.insets = new Insets(5,5,5,5);
        panelCustomerStatistics2.add(labelPhoneNumber, gbc);

        gbc.gridx = 1;
        gbc.gridy = 3;
        gbc.insets = new Insets(5,5,5,5);
        textPhoneNumber.setPreferredSize(new Dimension(100,25));
        panelCustomerStatistics2.add(textPhoneNumber,gbc);

        labelAddress = new JLabel("Address:", JLabel.RIGHT);
        labelAddress.setPreferredSize(new Dimension(100, 25));
        gbc.gridx = 0;
        gbc.gridy = 4;
        gbc.insets = new Insets(5,5,5,5);
        panelCustomerStatistics2.add(labelAddress, gbc);

        gbc.gridx = 1;
        gbc.gridy = 4;
        gbc.insets = new Insets(5,5,5,5);
        textAddress.setPreferredSize(new Dimension(100,25));
        panelCustomerStatistics2.add(textAddress,gbc);

        labelDiscount = new JLabel("Discount:", JLabel.RIGHT);
        labelDiscount.setPreferredSize(new Dimension(100, 25));
        gbc.gridx = 0;
        gbc.gridy = 5;
        gbc.insets = new Insets(5,5,5,5);
        panelCustomerStatistics2.add(labelDiscount, gbc);

        gbc.gridx = 1;
        gbc.gridy = 5;
        gbc.insets = new Insets(5,5,5,5);
        textDiscount.setPreferredSize(new Dimension(100,25));
        panelCustomerStatistics2.add(textDiscount,gbc);
        
        labelBought = new JLabel("Bought:", JLabel.RIGHT);
        labelBought.setPreferredSize(new Dimension(100,25));
        gbc.gridx = 0;
        gbc.gridy = 6;
        gbc.insets = new Insets(5,5,5,5);
        panelCustomerStatistics2.add(labelBought,gbc);
        
        gbc.gridx = 1;
        gbc.gridy = 6;
        gbc.insets = new Insets(5,5,5,5);
        textBought.setPreferredSize(new Dimension(100,25));
        panelCustomerStatistics2.add(textBought,gbc);
        
        labelLeased = new JLabel("Leased:", JLabel.RIGHT);
        labelLeased.setPreferredSize(new Dimension(100,25));
        gbc.gridx = 0;
        gbc.gridy = 7;
        gbc.insets = new Insets(5,5,5,5);
        panelCustomerStatistics2.add(labelLeased,gbc);
        
        gbc.gridx = 1;
        gbc.gridy = 7;
        gbc.insets = new Insets(5,5,5,5);
        textLeased.setPreferredSize(new Dimension(100,25));
        panelCustomerStatistics2.add(textLeased,gbc);
        
        labelTotal = new JLabel("Total:", JLabel.RIGHT);
        labelTotal.setPreferredSize(new Dimension(100,25));
        gbc.gridx = 0;
        gbc.gridy = 8;
        gbc.insets = new Insets(5,5,5,5);
        panelCustomerStatistics2.add(labelTotal,gbc);
        
        gbc.gridx = 1;
        gbc.gridy = 8;
        gbc.insets = new Insets(5,5,5,5);
        textTotal.setPreferredSize(new Dimension(100,25));
        panelCustomerStatistics2.add(textTotal,gbc);

        ok = new JButton("OK");
        ok.addActionListener(new ActionListener()
            {
                public void actionPerformed(ActionEvent e){
                    container = getContentPane();
                    container.removeAll();
                    customerStatistics();
                    container.invalidate();
                    container.revalidate();
                    container.repaint();
                    container.setVisible(true);
                }
            }
        );
        gbc.gridx = 0;
        gbc.gridy = 9;
        gbc.insets = new Insets(5,5,5,5);
        ok.setPreferredSize(new Dimension(100,25));
        panelCustomerStatistics2.add(ok,gbc);
    }
    
    public void customerStatisticsSecond(int id)
    {
        customerStatisticSecond(id);
        this.getContentPane().add(panelCustomerStatistics2, BorderLayout.NORTH);
    }
    
    public void mostSpendingCustomer(int id)
    {
        customerStatisticsSecond(id);
    }
    
    public void mostSpendingCustomerStatistics()
    {
        mostSpendingCustomer(statistics.mostSpendingCustomer());
        //this.getContentPane().add(panelMostSpendingCustomer, BorderLayout.NORTH);
    }
}